package com.shrct.businessprocess.purchase.impl;

import com.shrct.businessprocess.project.RCProjectMoney;
import com.shrct.businessprocess.purchase.RCBasePurchaseOrder;
import com.shrct.businessprocess.purchase.RCBudgetContract;
import com.shrct.businessprocess.purchase.RCProductDeliver;
import com.shrct.businessprocess.purchase.RCProductDeliverItem;
import com.shrct.businessprocess.purchase.RCPurchaseOrderCommissionPayProcess;
import com.shrct.businessprocess.purchase.RCPurchaseOrderPayProcess;
import com.shrct.businessprocess.purchase.RCPurchaseOrderProcess;
import com.shrct.businessprocess.purchase.RCPurchaseService;
import com.shrct.businessprocess.purchase.impl.RCPurchaseOrderCommissionPayProcessImpl;
import com.shrct.businessprocess.purchase.impl.RCPurchaseOrderPayProcessImpl;
import com.shrct.businessprocess.purchase.impl.RCPurchaseOrderProcessImpl;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Collection;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.purchase.RCPurchaseService")
public class RCPurchaseServiceImpl extends BaseService implements RCPurchaseService {
  @Autowired
  private IObjectFactory objectFactory;
  
  public RCPurchaseOrderProcess startPurchaseOrderProcess(final RCBasePurchaseOrder purchaseOrder) {
    RCPurchaseOrderProcess _create = RCPurchaseOrderProcessImpl.create(this.objectFactory);
    final Procedure1<RCPurchaseOrderProcess> _function = new Procedure1<RCPurchaseOrderProcess>() {
        public void apply(final RCPurchaseOrderProcess it) {
          it.start(purchaseOrder);
        }
      };
    RCPurchaseOrderProcess _doubleArrow = ObjectExtensions.<RCPurchaseOrderProcess>operator_doubleArrow(_create, _function);
    return _doubleArrow;
  }
  
  public RCPurchaseOrderPayProcess startPurchaseOrderPayProcess(final RCBasePurchaseOrder purchaseOrder, final RCProjectMoney amount, final String comment) {
    RCPurchaseOrderPayProcess _create = RCPurchaseOrderPayProcessImpl.create(this.objectFactory);
    final Procedure1<RCPurchaseOrderPayProcess> _function = new Procedure1<RCPurchaseOrderPayProcess>() {
        public void apply(final RCPurchaseOrderPayProcess it) {
          it.start(amount, purchaseOrder, comment);
        }
      };
    RCPurchaseOrderPayProcess _doubleArrow = ObjectExtensions.<RCPurchaseOrderPayProcess>operator_doubleArrow(_create, _function);
    return _doubleArrow;
  }
  
  public RCPurchaseOrderCommissionPayProcess startPurchaseOrderCommissionPayProcess(final RCBasePurchaseOrder purchaseOrder, final RCProjectMoney amount, final Double taxRate, final String comment) {
    RCPurchaseOrderCommissionPayProcess _create = RCPurchaseOrderCommissionPayProcessImpl.create(this.objectFactory);
    final Procedure1<RCPurchaseOrderCommissionPayProcess> _function = new Procedure1<RCPurchaseOrderCommissionPayProcess>() {
        public void apply(final RCPurchaseOrderCommissionPayProcess it) {
          it.start(amount, purchaseOrder, taxRate, comment);
        }
      };
    RCPurchaseOrderCommissionPayProcess _doubleArrow = ObjectExtensions.<RCPurchaseOrderCommissionPayProcess>operator_doubleArrow(_create, _function);
    return _doubleArrow;
  }
  
  public RCProductDeliver createDeliver(final String location, final Date deliverDate, final RCBudgetContract contract, final Procedure1<? super RCProductDeliver> init) {
    RCProductDeliver _xblockexpression = null;
    {
      RCProductDeliver _createAndAddtoDelivers = contract.createAndAddtoDelivers();
      final Procedure1<RCProductDeliver> _function = new Procedure1<RCProductDeliver>() {
          public void apply(final RCProductDeliver it) {
            it.setLocation(location);
          }
        };
      RCProductDeliver deliver = ObjectExtensions.<RCProductDeliver>operator_doubleArrow(_createAndAddtoDelivers, _function);
      init.apply(deliver);
      Collection<RCProductDeliverItem> _items = deliver.getItems();
      final Procedure1<RCProductDeliverItem> _function_1 = new Procedure1<RCProductDeliverItem>() {
          public void apply(final RCProductDeliverItem it) {
            it.performDeliver(deliverDate);
          }
        };
      IterableExtensions.<RCProductDeliverItem>forEach(_items, _function_1);
      _xblockexpression = (deliver);
    }
    return _xblockexpression;
  }
}
